<?php

/**
 * 搜索
 *
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/16
 * Time: 上午2:58
 */
class Search extends MY_Api_Controller
{
    /**
     * 搜索结果页
     */
    public function index()
    {
        $keyword   = trim($this->input->get_post('keyword'));
        $by_module = (int)$this->input->get_post('by_module');
        $page      = (int)$this->input->get_post('page');
        $limit     = (int)$this->input->get_post('limit');


        $this->load->service('common/service_common_search');
        $data = $this->service_common_search->index($keyword, $by_module, $page, $limit);


        $r_data = array();
        foreach ($data['data']['list'] as $k => $v)
        {
            $r_data[] = array
            (
                'bid'        => $v['business_id'],
                'b_pic'      => user_header($v['business_pic']),
                'b_title'    => $v['business_title'],
                'b_descr'    => $v['business_descr'],
                'ident'      => $v['ident'],
                'extend'     => $v['extend'],
                'is_public'  => $v['is_public'],
            );
        }


        $data['data']['list'] = $r_data;


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 搜索提醒
     */
    public function remind()
    {
        $keyword = trim($this->input->get_post('keyword'));


        $this->load->service('common/service_common_search');
        $data = $this->service_common_search->remind($keyword);


        $r_data = array();
        foreach ($data['data'] as $k => $v)
        {
            $r_data[] = array
            (
                'bid'   => $v['business_id'],
                'title' => $v['business_title'],
                'ident' => $v['ident'],
                'extend'=> $v['extend'],
            );
        }


        $this->json_output($r_data, $data['status']);
    }
}